//
//  LSRThemeViewModel.m
//  BaiSiProject
//
//  Created by lshenrong on 16/7/13.
//  Copyright © 2016年 lshenrong. All rights reserved.
//

#import "LSRThemeViewModel.h"
#import "LSRThemeItem.h"
#import "LSRCommentItem.h"


@implementation LSRThemeViewModel
-(void)setThemeItem:(LSRThemeItem *)themeItem
{   //没保存themeitem，看不到数据
    _themeItem= themeItem;
    //间距
    CGFloat margin=10;
    
    CGFloat textW=LSRScreenW-2*margin;
    
    CGFloat textY=55;
    
    CGFloat textH=[themeItem.text sizeWithFont:[UIFont systemFontOfSize:17] constrainedToSize:CGSizeMake(textW, MAXFLOAT)].height;
    
    CGFloat topViewX=0;
    CGFloat topViewY=0;
    CGFloat topViewW=LSRScreenW;
    CGFloat topViewH=textH+textY;
    
_topViewFrame=CGRectMake(topViewX,topViewY,topViewW,topViewH);
    
   _cellH=CGRectGetMaxY(_topViewFrame)+margin;

   //中间的图片View
    //不是段子，中间View的frame才需要计算
    if (themeItem.type!=LSRThemeTypeText) {
        CGFloat pictureViewX=margin;
        CGFloat pictureViewY= _cellH;
        CGFloat pictureViewW=textW;
        
        CGFloat pictureViewH=0;
        //themeItem.width>0判断图片是否存在
        if (themeItem.width>0) {
            
            pictureViewH=(textW/themeItem.width)*themeItem.height;
        }
        if (pictureViewH>LSRScreenH) {
            
            pictureViewH=300;
            themeItem.isBigPicture=YES;
        }
        
        self.themePictureFrame=CGRectMake(pictureViewX, pictureViewY, pictureViewW, pictureViewH);
        _cellH=CGRectGetMaxY(_themePictureFrame)+margin;
  
    }
    //设置热评frame
    if (themeItem.commentItem) {
        
    
        CGFloat commentX=margin;
        CGFloat commentY= _cellH;
        CGFloat commentW=textW;
        CGFloat commentH=42;
        if (themeItem.commentItem.content.length) {
           //总长度=名字+内容
CGFloat  H=[ themeItem.commentItem.totalContent sizeWithFont:[UIFont systemFontOfSize:17] constrainedToSize:CGSizeMake(commentW, MAXFLOAT)].height;
         //为了不遮盖到“最热评论”四个字,commentH=+21, commentH,都不行
            commentH= H+21;

            
        }
        self.commentFrame=CGRectMake(commentX, commentY, commentW, commentH);
         _cellH=CGRectGetMaxY(_commentFrame)+margin;
    }
    //底部工具条
    
     CGFloat bottomX=margin;
     CGFloat bottomY=_cellH;
     CGFloat bottomW=LSRScreenW;
     CGFloat bottomH=44;
    
    self.bottomViewFram=CGRectMake(bottomX, bottomY, bottomW, bottomH);
    
      _cellH=CGRectGetMaxY(_bottomViewFram)+margin;
}


@end
